
package com.sfdlJPush.controller;

import android.view.View;
import android.widget.TextView;

import com.sfdlJPush.R;
import com.sfdlJPush.api.ViewEnquiryRequest;
import com.sfdlJPush.api.ViewEnquiryResponse;
import com.sfdlJPush.controller.api.ApiListenrDefaultImpl;
import com.sfdlJPush.controller.api.B5MBaseResponse;
import com.sfdlJPush.model.Enquiry;
import com.sfdlJPush.utils.EventBus;
import com.sfdlJPush.utils.EventNames;

public class ViewEnquiryAndReplyFragment extends MainFragment
{
    private Enquiry enquiry;
    private ViewEnquiryRequest mViewEnquiryRequest;
    private TextView tv_subject, tv_from, tv_message, tv_time, tv_progress, tv_ip, tv_country, tv_regional, tv_product;
    private int position;

    @Override
    public int doGetContentViewId()
    {
        // TODO Auto-generated method stub
        return R.layout.viewenquiry;
    }

    @Override
    public void doInitSubViews(View containerView)
    {
        // TODO Auto-generated method stub
        tv_subject = (TextView) containerView.findViewById(R.id.tv_subject);
        tv_from = (TextView) containerView.findViewById(R.id.tv_from);
        tv_message = (TextView) containerView.findViewById(R.id.tv_message);
        tv_time = (TextView) containerView.findViewById(R.id.tv_time);
        tv_progress = (TextView) containerView.findViewById(R.id.tv_progress);
        tv_ip = (TextView) containerView.findViewById(R.id.tv_ip);
        tv_country = (TextView) containerView.findViewById(R.id.tv_country);
        tv_regional = (TextView) containerView.findViewById(R.id.tv_regional);
        tv_product = (TextView) containerView.findViewById(R.id.tv_product);
    }

    @Override
    public void doInitDataes()
    {
        // TODO Auto-generated method stub
        enquiry = (Enquiry) getArguments().getSerializable("enquiry");
        position = getArguments().getInt("position");
        mViewEnquiryRequest = new ViewEnquiryRequest(new ApiListenrDefaultImpl()
        {
            @Override
            public void onSuccess(B5MBaseResponse b5mBaseResponse)
            {
                // TODO Auto-generated method stub
                super.onSuccess(b5mBaseResponse);
                ViewEnquiryResponse viewEnquiryResponse = (ViewEnquiryResponse) b5mBaseResponse;
                setData(viewEnquiryResponse.enquiry);
                if (!"1".equals(enquiry.readFlag))
                {
                    EventBus.getInstance().notifiDataUpdate(EventNames.MESSAGE_HASREAD, position);
                }
            }
        }, mProgressBar);
    }

    protected void setData(Enquiry enquiry)
    {
        // TODO Auto-generated method stub
        tv_subject.setText(enquiry.title);
        tv_from.setText(enquiry.username);
        tv_message.setText(enquiry.content);
        tv_time.setText(enquiry.sendTime);
        tv_progress.setText(enquiry.progress);
        tv_ip.setText(enquiry.ip_address);
        tv_country.setText(enquiry.country);
        tv_regional.setText(enquiry.area);
        tv_product.setText(enquiry.title);
    }

    @Override
    public void doAfter()
    {
        // TODO Auto-generated method stub
        mViewEnquiryRequest.enquiryId = enquiry.enquiryId;
        mViewEnquiryRequest.start();
    }
}
